package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.entity.PowerModel;
import com.xieyingwangluo.yxpart.logic.PowerLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "power接口")
@Controller
@RequestMapping(value = "/api/v1/power")
public class PowerBaseRest extends BaseRest {
    @Autowired
    private PowerLogic powerLogic;

    //添加：接口(inface)、用户类型(customer_type)、权限(type)
    @ApiOperation(value = "添加权限", notes = "添加权限", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inface", value = "接口", required = true, dataType = "String", paramType = "query", defaultValue = "/api/v1/power"),
            @ApiImplicitParam(name = "customer_type", value = "用户类型", required = true, dataType = "int", paramType = "query", defaultValue = "25424"),
            @ApiImplicitParam(name = "type", value = "权限", required = true, dataType = "int", paramType = "query", defaultValue = "1")
    })
    @ResponseBody
    @PostMapping(value = "/add")
    public Result add(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      /*@RequestParam("inface") String inface,
                      @RequestParam("customer_type") int customer_type,
                      @RequestParam("type") int type*/
                      PowerModel powerModel
    ) {
        return powerLogic.add(powerModel);
    }

    //更改：接口(inface)、用户类型(customer_type)、权限(type)

    @ApiOperation(value = "修改权限", notes = "修改权限", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inface", value = "接口", required = true, dataType = "String", paramType = "query", defaultValue = "/api/v1/power"),
            @ApiImplicitParam(name = "customer_type", value = "用户类型", required = true, dataType = "int", paramType = "query", defaultValue = "25424"),
            @ApiImplicitParam(name = "type", value = "权限", required = true, dataType = "int", paramType = "query", defaultValue = "1")
    })
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result upd(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      /*@RequestParam("inface") String inface,
                      @RequestParam("customer_type") int customer_type,
                      @RequestParam("type") int type*/
                      PowerModel powerModel
    ) {
        return powerLogic.upd(powerModel);
    }

    //删除：权限编号(noid)

    @ApiOperation(value = "删除权限", notes = "删除权限", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "权限编号", required = true, dataType = "String", paramType = "query", defaultValue = "123456"),
    })
    @ResponseBody
    @DeleteMapping(value = "/del")
    public Result del(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                      @RequestParam("noid") String noid) {

        return powerLogic.del(noid);
    }

    //权限列表显示：

    @ApiOperation(value = "显示权限", notes = "显示权限", produces = "application/json")
    @ResponseBody
    @GetMapping(value = "/selA")
    public Result selA(PowerModel powerModel) {
        return powerLogic.selA(powerModel);
    }

    //权限显示(单条数据):noid(权限编号UUID)
    @ApiOperation(value = "权限显示", notes = "权限显示", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "权限编号", required = true, dataType = "String", paramType = "query", defaultValue = "123456"),
    })
    @ResponseBody
    @DeleteMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid) {

        return powerLogic.selO(noid);
    }
}
